package Threads.GeekBang_test;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

//FutureTask test
public class test_23 {
    public static void main(String[] args) {
        FutureTask<Integer> ft=new FutureTask<Integer>(()->{
            //callable
            System.out.println("calculate----");
            Thread.sleep(3000);
            System.out.println("calculate has been done");
            return 3;
        });
        new Thread(ft).start();
        new Thread(()->{
            System.out.println("attempt to get the res");
            int r=0;
            try {
                Integer res = ft.get();
                r=res;
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            System.out.println("i  get the res!");
            System.out.println(r+1);
        }).start();
    }

}
